Field of the Invention
The present invention relates to an image processing method of measuring a position of a workpiece from a search image, an image processing apparatus, a recording medium, and a method of manufacturing an assembly.
Description of the Related Art
An operation of finding a workpiece from within a search image obtained by capturing an image of the workpiece is one of functions commonly used in machine vision. Typical image processing for searching for a pattern from within an image in this way is template matching. In template matching, a feature of a pattern that a user wants to search for is prepared as a model in advance. Then, in the case where the pattern is searched for from within a search image obtained by capturing an image of a workpiece, a feature extracted from the search image is checked against a feature of the model prepared in advance. In many cases, as a feature, an edge which is information of the contour of a workpiece is used. Here, “edge” refers to a set of pixels in which there is an abrupt change in shade on an image, that is, a set of pixels in which an absolute value of an intensity gradient is not less than a certain threshold value.
Template matching is a method of searching for a position (including an orientation) on a search image, and the position is highly correlated with a model prepared in advance. Thus, in some cases, an edge which is noise exists in the vicinity of an edge, or part of an edge is missing or uneven. In such cases, a correlation value with the model does not reach a maximum value at a correct position on the search image, and the accuracy of position and orientation measurements may decrease.
As a method that solves such an issue, there is a method in which, in the case where a workpiece is circular or elliptical in shape, a position of the workpiece is measured with higher accuracy by performing circle fitting or ellipse fitting after searching for a temporary position of the workpiece through template matching or the like. Japanese Patent Laid-Open No. 2002-140713 discloses a method in which, in the case where a workpiece is circular in shape, a position of the workpiece is measured by setting a temporary center on a target image and performing fitting of a circle to an edge extracted from the target image.
In some cases, if an edge corresponding to an external shape of a workpiece cannot be used, a plurality of edges corresponding to a plurality of features other than the external shape of the workpiece are used. In such cases, fitting, such as circle fitting or ellipse fitting, is performed to center points of the respective edges.
In some cases, however, a shadow or the like appears in a captured image and hides features, and thus edge extraction fails, resulting in a reduction in the number of extracted edges. In the case where the number of edges usable as features of a workpiece is originally small, a reduction in the number of extracted edges reduces the accuracy of fitting, or makes fitting calculation impossible in some cases.